
----------------------------------------------------------------
-- Global Variables
----------------------------------------------------------------

EA_Window_UiProfileDelete = {}

local WINDOWNAME = "EA_Window_UiProfileDelete"
local m_selectedProfileName = L""

function EA_Window_UiProfileDelete.Begin()

    if( DoesWindowExist( WINDOWNAME ) )
    then
        return
    end

    -- Create the Window & Show it.
    CreateWindow( WINDOWNAME, true )

    EA_Window_ManageUiProfiles.UpdateProfileButtons()
end

function EA_Window_UiProfileDelete.End()

    if( not DoesWindowExist( WINDOWNAME ) )
    then
        return
    end

    -- Destroy the Window
    DestroyWindow( WINDOWNAME )
    
    m_selectedProfileName = L""
    
    EA_Window_ManageUiProfiles.UpdateProfileButtons()
end

function EA_Window_UiProfileDelete.Exists()
    return  DoesWindowExist( WINDOWNAME )
end


----------------------------------------------------------------
-- EA_Window_UiProfileDelete Functions
----------------------------------------------------------------

local m_selectedProfileName = L""

function EA_Window_UiProfileDelete.Initialize()

    m_selectedProfileName = EA_Window_ManageUiProfiles.GetSelectedProfileData().name

    LabelSetText( WINDOWNAME.."TitleBarText", GetStringFormatFromTable( "CustomizeUiStrings", StringTables.CustomizeUi.DELETE_UI_PROFILE_TITLE, { m_selectedProfileName }  ))   
    LabelSetText( WINDOWNAME.."Instructions", GetStringFromTable( "CustomizeUiStrings", StringTables.CustomizeUi.DELETE_UI_PROFILE_INTRUCTIONS ))   
    LabelSetText( WINDOWNAME.."Prompt", GetPregameString( StringTables.Pregame.LABEL_TYPE_Y_E_S ) )   
        
    --Buttons
    ButtonSetText( WINDOWNAME.."OkayButton", GetString( StringTables.Default.LABEL_OKAY ) )   
    ButtonSetText( WINDOWNAME.."CancelButton", GetString( StringTables.Default.LABEL_CANCEL ) )   
    
    EA_Window_UiProfileDelete.OnEditBoxTextChanged()
end

function EA_Window_UiProfileDelete.OnEditBoxTextChanged()

    -- Force The text to upper case
    local text = wstring.upper( EA_Window_UiProfileDeleteEditBox.Text )
    TextEditBoxSetText( WINDOWNAME.."EditBox", text ) 
        
    -- Disable the 'Okay' Button until the confirmation text has been typed sucessfully    
    
    local confirmationText =  GetPregameString( StringTables.Pregame.LABEL_CAPITAL_YES )
    local disabled = text ~= confirmationText
   
    ButtonSetDisabledFlag( WINDOWNAME.."OkayButton", disabled )

end

function EA_Window_UiProfileDelete.OnOkayButton()

    -- Do nothing if the button is disabled
    if( ButtonGetDisabledFlag( WINDOWNAME.."OkayButton" ) )
    then
        return
    end   
    
    -- Force the 'Okay' button to pressed.
    ButtonSetPressedFlag( WINDOWNAME.."OkayButton", true )

    -- Clear the selection
    EA_Window_ManageUiProfiles.SetSelectedProfile( nil )
    
    -- Delete the Profile
    CharacterSettingsRemoveUiProfile( m_selectedProfileName )
    
    EA_Window_UiProfileDelete.End()

end

function EA_Window_UiProfileDelete.OnCancelButton()
    EA_Window_UiProfileDelete.End()
end
